<template><div></div></template>
<script>
import Vue from 'vue'
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'
export default {
  props: {
    parent: String
  },
  created () {
    if (this.parent) {
      nprogress.configure({ parent: this.parent })
    }
    this.$router.beforeEach((to, from, next) => {
      nprogress.start()
      next()
    })
    this.$router.afterEach(() => {
      nprogress.done()
    })
    // Add a request interceptor
    Vue.axios.interceptors.request.use(function (config) {
      // Do something before request is sent
      nprogress.start()
      return config
    }, function (error) {
      // Do something with request error
      console.error(error)
      return Promise.reject(error)
    })

    // Add a response interceptor
    Vue.axios.interceptors.response.use(function (response) {
      // Do something with response data
      nprogress.done()
      return response
    }, function (error) {
      // Do something with response error
      console.error(error)
      return Promise.reject(error)
    })
  }
}
</script>
<style lang="stylus">
.nprogress-custom-parent #nprogress .spinner
#nprogress .spinner
  display none
</style>
